/**
 * 权限相关的数据
 * Created by gcc on 2017/9/29.
 */

import Vue from 'vue'
import {Tooltip} from "view-design";

// 页码相关
let page = {
  total: 1,
  startIndex: 0,
  stepNumber: 40,
  currentPage: 1
};

//页面状态相关
let status = {
  //搜索条件
  modalSearch: {
    isShow: false,
  },
  //搜索条件
  modalDetail: {
    isShow: false,
    title:""
  },
  uploadXml: {
    isUploading:false,
    percentage:0,
    btnMsg:"上传csv格式的查看产品详情记录文件",
    disabled:false
  }
};

// 和网络交互相关的参数
let params = {
  uploadFolderParam:{},
  //搜索条件
  searchParams:{
    startCreatedate:"",
    endCreatedate:"",
    productCode:"",
    categoryCode:"",
    categoryLevel: "",
  },
  detailParams:{
    inputKeyword:"",
    page:{
      total: 1,
      startIndex: 0,
      stepNumber: 40,
      currentPage: 1
    }
  },
  startEndDate: [],
};

// 页面的数据源
let data = {
  productVisitList: [],
  productDetailList:[],
  //从服务器返回的分类数据
  classificationList:[],
  //转换控件需要的分类数据
  categoryList:[],
  dateRange: {
    disabledDate (date) {
      return date && date.valueOf() > Date.now() - 86400000;
    }
  },
};

let table = function (self) {
  var titles = [

    {
      type: 'index',
      title: '#',
      align: 'center',
      width: 60
    },
    {
      title: '产品编码',
      key: 'productCode',
      align: 'center',
      width:200,
      render: (h, params) => {
        let productUrl = Vue.prototype.$tiyProductUrl(params.row.productCode);
        return h('div',[h('a',{
          attrs:{href:productUrl,target:'_blank'}
        },params.row.productCode)]);
      }
    },
    {
      title: '产品名称',
      key: 'productName',
      align: 'left',
      minWidth: 200,
    },
    {
      title: '产品图片',
      key: 'colorTryImg',
      width: 250,
      align: 'center',
      render: (h, params) => {
        {
          let imageUrl = params.row.productImg;
          let yunPath = Vue.prototype.$store.getters.imgPrefix;
          if(imageUrl){
            imageUrl = imageUrl;
            return h('div', [h('img', {
              attrs: {src: imageUrl, height: 60},
              on: {
                click: () => {
                  status.modalImage.url = imageUrl;
                  status.modalImage.isShow = true;
                }
              }
            }, imageUrl)
            ]);
          } else {
            return h('div',"");
          }
        }
      }
    },
    {
      title: '访问量',
      key: 'total',
      width: 120,
      align: 'center',
      render: (h, params) => {
        return (
          params.row.total == "0"
            ? <div>{params.row.total}</div>
            : <div>
              <a style="padding:6px;font-size:13px;color:#448aff" onClick={() => {
                self.getProductDetail(params.row);
              }}>
                {params.row.total}
              </a>
            </div>);
      }
    }
  ]

  return self.$authTableTitles(titles)
}

let detailTable = function (self) {
  let titles = [
    {
      type: 'index',
      title: '#',
      align: 'center',
      width: 60
    },
    {
      title: '用户名',
      key: 'userName',
      align: 'center',
      render: (h, params) => {
        let hideName = Vue.prototype.$tiyHideUsername(params.row.userName);
        return h('span',hideName)
      }
    },
    {
      title: '查看时间',
      key: 'eventTime',
      width: 160,
      align: 'center',
      render: (h, params) => {
        var date = new Date(params.row.eventTime);
        return h('div', self.$tiyBJTime(params.row.eventTime));
      }
    },
    {
      title: 'app版本',
      key: 'version',
      width: 120,
      align: 'center',
    },
    {
      title: '终端类型',
      key: 'deviceType',
      width: 120,
      align: 'center',
      render: (h, params) => {
        let device = '';
        switch(params.row.deviceType){
          case 1:
            device = 'Android';
            break;
          case 2:
            device = 'IOS';
            break;
          case 3:
            device = 'PC';
            break;
          case 4:
            device = 'Mobile PC';
            break;
          default:
            break;
        }
        return h('div', device);
      }
    },
    {
      title: '终端设备',
      key: 'device',
      align: 'center',
    },
  ]

  return self.$authTableTitles(titles)
}

export default  {
  tPage: page,
  tParams: params,
  tStatus: status,
  tableTitles: table,
  detailTableTitles: detailTable,
  tData: data
};
